package com.xinnet.mms.web;

import java.sql.SQLException;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.xinnet.core.utils.page.PageView;
import com.xinnet.mms.allot.dao.CustomAllotDao;
import com.xinnet.mms.allot.service.CustomAllotService;
import com.xinnet.mms.area.service.AreaService;
import com.xinnet.mms.common.AppGlobalContainer;
import com.xinnet.mms.config.dao.FlowTurnConfigDao;
import com.xinnet.mms.config.service.FlowTurnConfigService;
import com.xinnet.mms.contact.service.ContactService;
import com.xinnet.mms.customerManage.service.CustomerManageService;
import com.xinnet.mms.customerstate.service.CustomerStateHistService;
import com.xinnet.mms.dept.service.DeptService;
import com.xinnet.mms.deptproduct.service.DeptProductService;
import com.xinnet.mms.empcustomrelation.dao.EmpCustomRelationDao;
import com.xinnet.mms.entity.Area;
import com.xinnet.mms.entity.Contact;
import com.xinnet.mms.entity.CustomStateHist;
import com.xinnet.mms.entity.Customer;
import com.xinnet.mms.entity.Dept;
import com.xinnet.mms.entity.Emp;
import com.xinnet.mms.entity.Product;
import com.xinnet.mms.entity.Role;
import com.xinnet.mms.enums.AllotTypeEnmu;
import com.xinnet.mms.enums.ConsumeBusinessTypeEnmu;
import com.xinnet.mms.enums.ConsumeStateEnmu;
import com.xinnet.mms.enums.CustomerNatureEnmu;
import com.xinnet.mms.enums.CustomerStateEnmu;
import com.xinnet.mms.enums.CustomerTypeEnmu;
import com.xinnet.mms.enums.ProductTypeEnum;
import com.xinnet.mms.enums.TalkModeEnmu;
import com.xinnet.mms.login.service.EmpService;
import com.xinnet.mms.member.service.MemberService;
import com.xinnet.mms.order.service.OrderService;
import com.xinnet.mms.role.service.RoleService;
import com.xinnet.mms.shirosecurity.service.impl.ShiroDbRealm;
import com.xinnet.mms.utils.CustomerManage;

/**
 * 
 * 类描述：用于菜单树节点跳转的Controller
 * 
 * @author 李丽华[lilihua@xinnet.com]
 * 
 * @version 1.0
 * 
 * @since 2014-1-15
 */
@Controller
@RequestMapping("/page")
public class PageController {

	@Autowired
	private CustomAllotDao customAllotDao;
	
	@Autowired
	private CustomAllotService customAllotService;

	@Autowired
	private CustomerManageService customerManageService;

	@Autowired
	private DeptService deptService;

	@Autowired
	private AreaService areaService;

	@Autowired
	FlowTurnConfigService flowTurnConfigService;

	@Autowired
	CustomerStateHistService customerStateHistService;
	@Autowired
	EmpService empService;

	@Autowired
	RoleService roleService;

	@Autowired
	MemberService memberService;
	
	@Autowired
	FlowTurnConfigDao flowTurnConfigDao;
	
	@Autowired
	EmpCustomRelationDao empCustomRelationDao;
	
	@Autowired
	DeptProductService deptProductService;
	
	@Autowired
	OrderService orderService;
	
	@Autowired
	ContactService contactService;

	ObjectMapper mapper = new ObjectMapper();
	private static Log log = LogFactory.getLog(PageController.class);
	/**
	 * 
	 * 方法描述：框架head
	 * 
	 * @return
	 * 
	 * @author 李丽华[lilihua@xinnet.com]
	 * 
	 *         2014-2-10 下午3:51:51
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goHead")
	public String goHead() {
		return "market/head";
	}

	/**
	 * 
	 * 方法描述：框架menu
	 * 
	 * @return
	 * 
	 * @author 李丽华[lilihua@xinnet.com]
	 * 
	 *         2014-2-10 下午3:51:51
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goMenu")
	public String goMenu() {
		return "market/menu";
	}

	/**
	 * 
	 * 方法描述：框架main 前往该页面的时候 查询出各个类型的未接收客户数量 以及推送统计
	 * 
	 * @return
	 * 
	 * @author 李丽华[lilihua@xinnet.com]
	 * 
	 *         2014-2-10 下午3:51:51
	 * @throws Exception
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goMain")
	public String goMain(HttpSession session, Model model) throws Exception {
		// 获取当前登录用户
		log.info("执行gomain方法");
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			log.info("gomain 里面currentUser为空");
			return "redirect:/login/loginPage";
		}
		log.info(currentUser.getEname()+"正在进入主页，sessionID:"+session.getId());
		//获取角色
		Role role = roleService.getRoleById(currentUser.getRolId());
		log.info("gomain 里面获取到role");
		session.setAttribute("role", role);
		log.info("gomain 里面已经获取到role");
		//客户类型
		//服务期客户
		Integer serviceCustomer = CustomerManage.SERVICE_CUSTOMER;
		model.addAttribute("serviceCustomer", serviceCustomer);
		
		//新注册客户
		Integer newCustomer = CustomerManage.NEW_CUSTOMER;
		model.addAttribute("newCustomer", newCustomer);
		
		//意向客户
		Integer intentionCustomer = CustomerManage.INTENTION_CUSTOMER;
		model.addAttribute("intentionCustomer", intentionCustomer);
		
		//二次开发客户
		Integer twiceCustomer = CustomerManage.TWICE_CUSTOMER;
		model.addAttribute("twiceCustomer", twiceCustomer);
		
		//未注册新客户
		Integer notRegisterNewCustomer = CustomerManage.NOT_REGISTER_NEW_CUSTOMER;
		model.addAttribute("notRegisterNewCustomer", notRegisterNewCustomer);
		
		return "market/main";
	}
	


	/**
	 * 
	 * 方法描述：框架foot
	 * 
	 * @return
	 * 
	 * @author 李丽华[lilihua@xinnet.com]
	 * 
	 *         2014-2-10 下午3:51:51
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goFoot")
	public String goFoot() {
		return "market/foot";
	}

	// =============================================================客户管理
	/**
	 * 服务期客户
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goServiceCustomer")
	public String goServiceCustomer(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		log.info(currentUser.getEname()+"正在查看服务期客户，sessionID:"+session.getId());
		// 客户管理查询条件：所属人的部门组织Ztree Json
		String deptJson = AppGlobalContainer.deptIdToDeptJsonMap.get(currentUser.getId());
		if(deptJson==null){
			deptJson = "["
					+ deptService.getDeptTreeByDeptId(currentUser.getId()) + "]";
			AppGlobalContainer.deptIdToDeptJsonMap.put(currentUser.getId(), deptJson);
		}
		model.addAttribute("deptJson", deptJson);

		// 客户管理查询条件：所属区域
		List<Area> parentAreaList = areaService.getAreaOfClassA();
		model.addAttribute("parentAreaList", parentAreaList);

		List<Area> childAreaList = areaService.getAreaOfClassB();
		model.addAttribute("childAreaList", childAreaList);
		
		Integer customerType = CustomerManage.SERVICE_CUSTOMER;
		model.addAttribute("customerType", customerType);
		
		ProductTypeEnum[] productTypeEnumArray = ProductTypeEnum.values();
		model.addAttribute("productTypeEnumArray", productTypeEnumArray);
		
		ConsumeBusinessTypeEnmu[] consumeBusinessTypeEnmu = ConsumeBusinessTypeEnmu.values();
		model.addAttribute("consumeBusinessTypeEnmu", consumeBusinessTypeEnmu);

		ConsumeStateEnmu[] consumeStateEnmu = ConsumeStateEnmu.values();
		model.addAttribute("consumeStateEnmu", consumeStateEnmu);
		Customer c = new Customer();
		c.setCustomId("--");
		model.addAttribute("customer", c);
		return "market/customer/service_customer";
	}

	/**
	 * 客户详情
	 * 
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goCustomerDetails")
	public String goCustomerDetails(HttpSession session, String customId, Integer customerType,
			Model model) throws Exception {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		
		model.addAttribute("customId", customId);
		
		// 客户基本信息
		Customer customerInfo = memberService.getMemberByCusId(customId);
		Contact contact = new Contact();
		contact.setCusId(customId);
		contact = contactService.queryContact(contact);
		// 推送详情
		PageView<CustomStateHist> pushDetailsPageView = customerStateHistService
				.getCustomStateHistByCustomId(new PageView<CustomStateHist>(1), customId);
		List<CustomStateHist> customStateHistList = pushDetailsPageView.getRecords();
		Emp emp = null;
		Product product = null;
		for (CustomStateHist customStateHist : customStateHistList) {
			emp = empService.getEmpbyEmpno(customStateHist.getPusherId());
			product = customerManageService
					.getProductByProductId(customStateHist.getProductId());
			if (null != emp) {
				customStateHist.setPusherName(emp.getEname());
			} else {
				customStateHist.setPusherName("系统");
			}

			// 设置客户类型
			customStateHist.setCustomerTypeStr(CustomerTypeEnmu
						.getCustomerTypeEnmuByValue(customStateHist.getCustomType())
						.getLabel());
			if (null != product) {
				customStateHist.setProductName(product.getProductName());
			}
		}
		
		//客户基本信息
		model.addAttribute("customerInfo", customerInfo);
		model.addAttribute("customerContact", contact);
		//客户购买商品列表
//		model.addAttribute("buyGoodsList", buyGoodsList);
//		model.addAttribute("buyGoodsPageView", buyGoodsPageView);
		
		// 推送详情列表
		model.addAttribute("customStateHistList", customStateHistList);
		model.addAttribute("pushDetailsPageView", pushDetailsPageView);
		/*//按创建时间排序
		Collections.sort(contactList, new Comparator<Contact>(){

			@Override
			public int compare(Contact c1, Contact c2) {
				
				return c2.getCreateTime().compareTo(c1.getCreateTime());
			}
		});*/
		
		//model.addAttribute("contactList", contactList);
		ProductTypeEnum[] productTypeEnumArray = ProductTypeEnum.values();
		model.addAttribute("productTypeEnumArray", productTypeEnumArray);
		
		ConsumeBusinessTypeEnmu[] consumeBusinessTypeEnmu = ConsumeBusinessTypeEnmu.values();
		model.addAttribute("consumeBusinessTypeEnmu", consumeBusinessTypeEnmu);

		ConsumeStateEnmu[] consumeStateEnmu = ConsumeStateEnmu.values();
		model.addAttribute("consumeStateEnmu", consumeStateEnmu);
		//交流方式
		CustomerNatureEnmu[] customerNatureEnmu = CustomerNatureEnmu.values();
		model.addAttribute("customerNatureEnmu", customerNatureEnmu);
		// 由哪个页面进入的
		String page = null;
		String pageUrl = null;
		if (null != customerType) {

			if (customerType.equals(CustomerManage.SERVICE_CUSTOMER)) {
				page = "服务期客户";
				pageUrl = "goServiceCustomer";
			}

			if (customerType.equals(CustomerManage.DUE_SOON_CUSTOMER)) {
				page = "即将到期商品";
				pageUrl = "goDueSoonCustomer";
			}

			if (customerType.equals(CustomerManage.INTENTION_CUSTOMER)) {
				page = "意向客户";
				pageUrl = "goIntentionCustomer";
			}

			if (customerType.equals(CustomerManage.NEW_CUSTOMER)) {
				page = "新注册客户";
				pageUrl = "goNewRegisterCustomer";
			}

			if (customerType.equals(CustomerManage.TWICE_CUSTOMER)) {
				page = "二次开发客户";
				pageUrl = "goTwiceCustomer";
			}

			if (customerType.equals(CustomerManage.OPEN_SEA_CUSTOMER)) {
				page = "公海客户";
				pageUrl = "goOpenseaCustomer";
			}

			if (customerType.equals(CustomerManage.RECYCLING_CUSTOMER)) {
				page = "回收客户";
				pageUrl = "goRecyclingCustomer";
			}

			if (customerType.equals(CustomerManage.NOT_REGISTER_NEW_CUSTOMER)) {
				page = "未注册新客户";
				pageUrl = "goNotRegisterNewCustomer";
			}
		}


		model.addAttribute("page", page);
		model.addAttribute("pageUrl", pageUrl);

		return "market/customer/customer_details";
	}

	/**
	 * 
	 * 方法描述：即将到期客户
	 * 
	 * @return
	 * 
	 * @author 李丽华[lilihua@xinnet.com]
	 * 
	 *         2014-2-11 下午1:56:34
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goDueSoonCustomer")
	public String goDueSoonCustomer(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		// 客户管理查询条件：所属人的部门组织Ztree Json
		String deptJson = AppGlobalContainer.deptIdToDeptJsonMap.get(currentUser.getId());
		if(deptJson==null){
			deptJson = "["
					+ deptService.getDeptTreeByDeptId(currentUser.getId()) + "]";
			AppGlobalContainer.deptIdToDeptJsonMap.put(currentUser.getId(), deptJson);
		}
		model.addAttribute("deptJson", deptJson);

		// 客户管理查询条件：所属区域
		List<Area> parentAreaList = areaService.getAreaOfClassA();
		model.addAttribute("parentAreaList", parentAreaList);

		List<Area> childAreaList = areaService.getAreaOfClassB();
		model.addAttribute("childAreaList", childAreaList);

		Integer customerType = CustomerManage.DUE_SOON_CUSTOMER;
		model.addAttribute("customerType", customerType);

		String deptIdStr = deptService.getChildNodeId(currentUser.getId());
		List<Product> productList = deptProductService.getProductListByDeptIdStr(deptIdStr);
		
		model.addAttribute("productList", productList);
		
		ProductTypeEnum[] productTypeEnumArray = ProductTypeEnum.values();
		model.addAttribute("productTypeEnumArray", productTypeEnumArray);

		ConsumeBusinessTypeEnmu[] consumeBusinessTypeEnmu = ConsumeBusinessTypeEnmu.values();
		model.addAttribute("consumeBusinessTypeEnmu", consumeBusinessTypeEnmu);

		ConsumeStateEnmu[] consumeStateEnmu = ConsumeStateEnmu.values();
		model.addAttribute("consumeStateEnmu", consumeStateEnmu);
		Customer c = new Customer();
		c.setCustomId("--");
		model.addAttribute("customer", c);
		return "market/customer/due_soon_customer";
	}

	/**
	 * 新注册客户
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goNewRegisterCustomer")
	public String goNewCus(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		log.info(currentUser.getEname()+"正在查看新注册客户，sessionID:"+session.getId());
		// 客户管理查询条件：所属人的部门组织Ztree Json
		String deptJson = AppGlobalContainer.deptIdToDeptJsonMap.get(currentUser.getId());
		if(deptJson==null){
			deptJson = "["
					+ deptService.getDeptTreeByDeptId(currentUser.getId()) + "]";
			AppGlobalContainer.deptIdToDeptJsonMap.put(currentUser.getId(), deptJson);
		}
		model.addAttribute("deptJson", deptJson);

		// 客户管理查询条件：所属区域
		List<Area> parentAreaList = areaService.getAreaOfClassA();
		model.addAttribute("parentAreaList", parentAreaList);

		List<Area> childAreaList = areaService.getAreaOfClassB();
		model.addAttribute("childAreaList", childAreaList);

		Integer customerType = CustomerManage.NEW_CUSTOMER;

		CustomerStateEnmu[] customerStateEnmuArray = CustomerStateEnmu.values();
		AllotTypeEnmu[] allotTypeEnmuArray = AllotTypeEnmu.values();

		ProductTypeEnum[] productTypeEnumArray = ProductTypeEnum.values();
		model.addAttribute("productTypeEnumArray", productTypeEnumArray);

		model.addAttribute("customerType", customerType);
		model.addAttribute("customerStateEnmuArray", customerStateEnmuArray);
		model.addAttribute("allotTypeEnmuArray", allotTypeEnmuArray);
		
		ConsumeBusinessTypeEnmu[] consumeBusinessTypeEnmu = ConsumeBusinessTypeEnmu.values();
		model.addAttribute("consumeBusinessTypeEnmu", consumeBusinessTypeEnmu);

		ConsumeStateEnmu[] consumeStateEnmu = ConsumeStateEnmu.values();
		model.addAttribute("consumeStateEnmu", consumeStateEnmu);
		Customer c = new Customer();
		c.setCustomId("--");
		model.addAttribute("customer", c);
		return "market/customer/new_register_customer";
	}

	/**
	 * 意向客户
	 * 
	 * @return
	 */
	@RequestMapping("/goIntentionCustomer")
	public String goIntentionCustomer(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		// 客户管理查询条件：所属人的部门组织Ztree Json
		String deptJson = AppGlobalContainer.deptIdToDeptJsonMap.get(currentUser.getId());
		if(deptJson==null){
			deptJson = "["
					+ deptService.getDeptTreeByDeptId(currentUser.getId()) + "]";
			AppGlobalContainer.deptIdToDeptJsonMap.put(currentUser.getId(), deptJson);
		}
		model.addAttribute("deptJson", deptJson);

		// 客户管理查询条件：所属区域
		List<Area> parentAreaList = areaService.getAreaOfClassA();
		model.addAttribute("parentAreaList", parentAreaList);

		List<Area> childAreaList = areaService.getAreaOfClassB();
		model.addAttribute("childAreaList", childAreaList);

		Integer customerType = CustomerManage.INTENTION_CUSTOMER;
		model.addAttribute("customerType", customerType);

		ProductTypeEnum[] productTypeEnumArray = ProductTypeEnum.values();
		model.addAttribute("productTypeEnumArray", productTypeEnumArray);
		return "market/customer/intention_customer";
	}
	
	/**
	 * 进入我的客户
	 * 
	 * @return
	 */
	@RequestMapping("/goMyCustomer")
	public String goMyCustomer(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		
		return "market/customer/mycustomer";
	}
	
	/**
	 * 进入客户查询(经理及以上角色可查)
	 * 
	 * @return
	 */
	@RequestMapping("/goCustomerQuery")
	public String goCustomerQuery(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		// 客户管理查询条件：所属人的部门组织Ztree Json
		String deptJson = AppGlobalContainer.deptIdToDeptJsonMap.get(currentUser.getId());
		if(deptJson==null){
			deptJson = "["
					+ deptService.getDeptTreeByDeptId(currentUser.getId()) + "]";
			AppGlobalContainer.deptIdToDeptJsonMap.put(currentUser.getId(), deptJson);
		}
		model.addAttribute("deptJson", deptJson);
		
		CustomerTypeEnmu[] customerTypeEnmuArray = CustomerTypeEnmu.values();
		model.addAttribute("customerTypeEnmuArray", customerTypeEnmuArray);
		return "market/customer/customer";
	}

	/**
	 * 潜在客户报备库
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goReportedCustomer")
	public String goReportedCus(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		// 客户管理查询条件：所属人的部门组织Ztree Json
		String deptJson = AppGlobalContainer.deptIdToDeptJsonMap.get(currentUser.getId());
		if(deptJson==null){
			deptJson = "["
					+ deptService.getDeptTreeByDeptId(currentUser.getId()) + "]";
			AppGlobalContainer.deptIdToDeptJsonMap.put(currentUser.getId(), deptJson);
		}
		model.addAttribute("deptJson", deptJson);

		// 客户管理查询条件：所属区域
		List<Area> parentAreaList = areaService.getAreaOfClassA();
		model.addAttribute("parentAreaList", parentAreaList);

		List<Area> childAreaList = areaService.getAreaOfClassB();
		model.addAttribute("childAreaList", childAreaList);

		Integer customerType = CustomerManage.REPORTED_CUSTOMER;
		model.addAttribute("customerType", customerType);
		ConsumeBusinessTypeEnmu[] consumeBusinessTypeEnmu = ConsumeBusinessTypeEnmu.values();
		model.addAttribute("consumeBusinessTypeEnmu", consumeBusinessTypeEnmu);
		ProductTypeEnum[] productTypeEnumArray = ProductTypeEnum.values();
		model.addAttribute("productTypeEnumArray", productTypeEnumArray);
		ConsumeStateEnmu[] consumeStateEnmu = ConsumeStateEnmu.values();
		model.addAttribute("consumeStateEnmu", consumeStateEnmu);
		return "market/customer/reported_customer";
	}

	/**
	 * 创建报备客户
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goAddReportedCustomer")
	public String goAddReportedCustomer(HttpServletRequest request,
			HttpServletResponse response, String cusId, String name,
			String phone, String email) {
		Customer customer = new Customer();
		customer.setCname(name);
		customer.setPhone(phone);
		customer.setEmail(email);
		customer.setCusId(cusId);
		request.getSession().setAttribute("customer", customer);
		return "market/customer/add_reported_customer";
	}

	/**
	 * 创建报备客户
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goToAddReportedCustomer")
	public String goAddReportedCustomer() {
		return "market/customer/add_reported_customer";
	}

	/**
	 * 修改报备客户
	 * 
	 * @return
	 * @throws Exception
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goUpdateReportedCustomer")
	public String goUpdateReportedCustomer(String customId, Model model)
			throws Exception {
		Customer customer = customAllotService.getCustomerById(customId);
		model.addAttribute("customer", customer);
		return "market/customer/update_reported_customer";
	}

	/**
	 * 二次开发客户
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goTwiceCustomer")
	public String goRedevelCus(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		// 客户管理查询条件：所属人的部门组织Ztree Json
		String deptJson = AppGlobalContainer.deptIdToDeptJsonMap.get(currentUser.getId());
		if(deptJson==null){
			deptJson = "["
					+ deptService.getDeptTreeByDeptId(currentUser.getId()) + "]";
			AppGlobalContainer.deptIdToDeptJsonMap.put(currentUser.getId(), deptJson);
		}
		model.addAttribute("deptJson", deptJson);

		// 客户管理查询条件：所属区域
		List<Area> parentAreaList = areaService.getAreaOfClassA();
		model.addAttribute("parentAreaList", parentAreaList);

		List<Area> childAreaList = areaService.getAreaOfClassB();
		model.addAttribute("childAreaList", childAreaList);
		
		CustomerStateEnmu[] customerStateEnmuArray = CustomerStateEnmu.values();
		model.addAttribute("customerStateEnmuArray", customerStateEnmuArray);

		Integer customerType = CustomerManage.TWICE_CUSTOMER;
		model.addAttribute("customerType", customerType);
		return "market/customer/twice_customer";
	}

	/**
	 * 公海客户
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goOpenseaCustomer-xxx")
	public String goOpenseaCus(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		// 客户管理查询条件：所属人的部门组织Ztree Json
		String deptJson = AppGlobalContainer.deptIdToDeptJsonMap.get(currentUser.getId());
		if(deptJson==null){
			deptJson = "["
					+ deptService.getDeptTreeByDeptId(currentUser.getId()) + "]";
			AppGlobalContainer.deptIdToDeptJsonMap.put(currentUser.getId(), deptJson);
		}
		model.addAttribute("deptJson", deptJson);

		// 客户管理查询条件：所属区域
		List<Area> parentAreaList = areaService.getAreaOfClassA();
		model.addAttribute("parentAreaList", parentAreaList);

		List<Area> childAreaList = areaService.getAreaOfClassB();
		model.addAttribute("childAreaList", childAreaList);
		ProductTypeEnum[] productTypeEnumArray = ProductTypeEnum.values();
		model.addAttribute("productTypeEnumArray", productTypeEnumArray);
		Integer customerType = CustomerManage.OPEN_SEA_CUSTOMER;
		model.addAttribute("customerType", customerType);
		ConsumeBusinessTypeEnmu[] consumeBusinessTypeEnmu = ConsumeBusinessTypeEnmu.values();
		model.addAttribute("consumeBusinessTypeEnmu", consumeBusinessTypeEnmu);

		ConsumeStateEnmu[] consumeStateEnmu = ConsumeStateEnmu.values();
		model.addAttribute("consumeStateEnmu", consumeStateEnmu);
		Customer c = new Customer();
		c.setCustomId("--");
		model.addAttribute("customer", c);
		return "market/customer/open_sea_customer_jqGrid";
	}
	
	/**
	 * 新版公海客户
	 * 
	 * 2016年12月7日09:57:52 
	 * 
	 * 邢泽江
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goOpenseaCustomer")
	public String goOpenseaCustomerJqGrid(HttpSession session, Model model) {
		
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		// 获取登录用户权限下的 分公司列表
		String deptid = currentUser.getId();
		Dept dept = deptService.getDeptByDeptId(deptid);
		model.addAttribute("companyList", dept.getUnUsedCompanyList());
		
		List<Area> childAreaList = areaService.getAreaOfClassB();
		model.addAttribute("childAreaList", childAreaList);
		
		

		return "market/customer/open_sea_customer_jqGrid";
	}

	/**
	 * 回收客户
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goRecyclingCustomer")
	public String goRecyclingCustomer(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		// 客户管理查询条件：所属人的部门组织Ztree Json
		String deptJson = AppGlobalContainer.deptIdToDeptJsonMap.get(currentUser.getId());
		if(deptJson==null){
			deptJson = "["
					+ deptService.getDeptTreeByDeptId(currentUser.getId()) + "]";
			AppGlobalContainer.deptIdToDeptJsonMap.put(currentUser.getId(), deptJson);
		}
		model.addAttribute("deptJson", deptJson);

		// 客户管理查询条件：所属区域
		List<Area> parentAreaList = areaService.getAreaOfClassA();
		model.addAttribute("parentAreaList", parentAreaList);

		List<Area> childAreaList = areaService.getAreaOfClassB();
		model.addAttribute("childAreaList", childAreaList);
		ConsumeBusinessTypeEnmu[] consumeBusinessTypeEnmu = ConsumeBusinessTypeEnmu.values();
		model.addAttribute("consumeBusinessTypeEnmu", consumeBusinessTypeEnmu);
		ProductTypeEnum[] productTypeEnumArray = ProductTypeEnum.values();
		model.addAttribute("productTypeEnumArray", productTypeEnumArray);
		ConsumeStateEnmu[] consumeStateEnmu = ConsumeStateEnmu.values();
		model.addAttribute("consumeStateEnmu", consumeStateEnmu);
		Integer customerType = CustomerManage.RECYCLING_CUSTOMER;
		model.addAttribute("customerType", customerType);
		Customer c = new Customer();
		c.setCustomId("--");
		model.addAttribute("customer", c);
		return "market/customer/recycling_customer";
	}

	/**
	 * 未注册新客户
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goNotRegisterNewCustomer")
	public String goNotRegisterCustomer(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		// 客户管理查询条件：所属人的部门组织Ztree Json
		String deptJson = AppGlobalContainer.deptIdToDeptJsonMap.get(currentUser.getId());
		if(deptJson==null){
			deptJson = "["
					+ deptService.getDeptTreeByDeptId(currentUser.getId()) + "]";
			AppGlobalContainer.deptIdToDeptJsonMap.put(currentUser.getId(), deptJson);
		}
		model.addAttribute("deptJson", deptJson);

		// 客户管理查询条件：所属区域
		List<Area> parentAreaList = areaService.getAreaOfClassA();
		model.addAttribute("parentAreaList", parentAreaList);

		List<Area> childAreaList = areaService.getAreaOfClassB();
		model.addAttribute("childAreaList", childAreaList);
		
		ProductTypeEnum[] productTypeEnumArray = ProductTypeEnum.values();
		model.addAttribute("productTypeEnumArray", productTypeEnumArray);

		Integer customerType = CustomerManage.NOT_REGISTER_NEW_CUSTOMER;
		model.addAttribute("customerType", customerType);
		ConsumeBusinessTypeEnmu[] consumeBusinessTypeEnmu = ConsumeBusinessTypeEnmu.values();
		model.addAttribute("consumeBusinessTypeEnmu", consumeBusinessTypeEnmu);

		ConsumeStateEnmu[] consumeStateEnmu = ConsumeStateEnmu.values();
		model.addAttribute("consumeStateEnmu", consumeStateEnmu);
		Customer c = new Customer();
		c.setCustomId("--");
		model.addAttribute("customer", c);
		return "market/customer/not_register_new_customer";
	}

	/**
	 * 即将流走客户
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goVanishSoonCustomer")
	public String goVanishSoonCustomer(HttpSession session, Model model) {
		Emp currentUser = (Emp) session.getAttribute("currentUser");
		if (null == currentUser) {
			return "redirect:/login/loginPage";
		}
		// 客户管理查询条件：所属人的部门组织Ztree Json
		String deptJson = AppGlobalContainer.deptIdToDeptJsonMap.get(currentUser.getId());
		if(deptJson==null){
			deptJson = "["
					+ deptService.getDeptTreeByDeptId(currentUser.getId()) + "]";
			AppGlobalContainer.deptIdToDeptJsonMap.put(currentUser.getId(), deptJson);
		}
		model.addAttribute("deptJson", deptJson);

		// 客户管理查询条件：所属区域
		List<Area> parentAreaList = areaService.getAreaOfClassA();
		model.addAttribute("parentAreaList", parentAreaList);

		List<Area> childAreaList = areaService.getAreaOfClassB();
		model.addAttribute("childAreaList", childAreaList);

		Integer customerType = CustomerManage.VANISH_SOON_CUSTOMER;
		CustomerTypeEnmu[] customerTypeEnmuArray = CustomerTypeEnmu.values();
		model.addAttribute("customerType", customerType);
		model.addAttribute("customerTypeEnmuArray", customerTypeEnmuArray);
		return "market/customer/vanish_soon_customer";
	}

	// =============================================================我的业绩
	/**
	 * 业绩统计
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goPerformanceStat")
	public String goPerformanceStat() {
		return "market/achieve/achieve";
	}

	/**
	 * 订单明细
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goOrderDetail")
	public String goOrderDetail() {
		return "market/achieve/bill";
	}

	/**
	 * 到期商品统计
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goDueProductStat")
	public String goDueProductStat() {
		return "market/achieve/goods";
	}

	/**
	 * 推送成交率统计
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goPushedTransactionRate")
	public String goPushedTransactionRate() {
		return "market/achieve/tuisong";
	}

	// =============================================================权限管理
	/**
	 * 资源管理
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goResourceManage")
	public String goResourceManage() {
		return "market/authority/ziyuan_index";
	}

	/**
	 * 角色管理
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goRoleManage")
	public String goRoleManage() {
		return "market/authority/juese_index";
	}

	/**
	 * 员工管理
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goEmpManage")
	public String goEmpManage() {
		return "market/authority/yuangong_index";
	}

	/**
	 * 部门管理
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goDeptManage")
	public String goDeptManage() {
		return "market/authority/bumen_index";
	}

	// =============================================================规则设定
	/**
	 * 客户调配
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goCustomerDeploy")
	public String goCustomerDeploy() {
		return "market/rule/bumen_index";
	}

	/**
	 * 客户分配规则
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goCustomerAllotRule")
	public String goCustomerAllotRule() {
		return "market/rule/fenpei_modify";
	}

	/**
	 * 客户流转规则
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goCustomerCirculationRule")
	public String goCustomerCirculationRule() {
		return "market/rule/liuzhuan_modify";
	}

	/**
	 * 数据核算规则
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goDataCheckRule")
	public String goDataCheckRule() {
		return "market/rule/shuju_modify";
	}

	// =============================================================审核功能
	/**
	 * 客户分配审核
	 * 
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goCheckCustomerAllot")
	public String goCheckCustomerAllot() {
		return "market/check_u/check_fp";
	}

	/**
	 * 客户流转审核
	 * 
	 * @return
	 */
	 @Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goCheckCustomerCirculation")
	public String goCheckCustomerCirculation() {
		return "market/check_u/check_lz";
	}

	/**
	 * 数据核算审核
	 * 
	 * @return
	 */
	 @Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goCheckData")
	public String goCheckData() {
		return "market/check_u/check_sj";
	}

	/**
	 * 
	 * 功能描述：打开业务员个人信息
	 * 
	 * @return
	 * 
	 * @author 王湛智[wangzhanzhi@xinnet.com]
	 * 
	 * @since 2014年2月27日
	 * 
	 * @update:[变更日期YYYY-MM-DD][更改人姓名][变更描述]
	 */
	 @Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/empInfo")
	public String goEmpInfo() {
		return "market/util/empinfo";
	}
	
	 /*/
	  * 功能描述：打开我的工作台
	  */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/workbench")
	public String alloRecord(){
		return "market/customer/myworkbench";
	}
	
	/**
	 * 打开调配记录查询页面
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/allotRecord")
	public String openMyworkbench(){
		return "market/customer/allot_record";
	}
	
	/**
	 * 打开调配接收页面
	 * @return
	 */
	@Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/allotList")
	public String openAllotList(){
		return "market/customer/ReceiveList";
	}
	
	/**
	 * 数据核算审核
	 * 
	 * @return
	 */
	 @Transactional(propagation=Propagation.REQUIRED,readOnly=true)
	@RequestMapping("/goCustomerStateHistory")
	public String goCustomerStateHistory() {
		return "market/customer/customer_state_history";
	}
	
}
